/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import business.CarDetailBusiness;
import business.FlightBusiness;
import business.HotelsBusiness;
import business.TourBusiness;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import model.CarDetails;
import model.Flight;
import model.Hotels;
import model.PackageTour;

/**
 *
 * @author Administrator
 */
@ManagedBean
@RequestScoped
public class CustomerSearchBean {

    private HotelsBusiness hotelsBusiness = new HotelsBusiness();
    private FlightBusiness flightBusiness = new FlightBusiness();
    private CarDetailBusiness carDetailBusiness = new CarDetailBusiness();
    private TourBusiness tourBusiness = new TourBusiness();
//-------------------------------Search Hotel --------------------------------
    private List<Hotels> listHotel;
    private String searchHotelString;
    private String placeNameString;
    private float priceFrom;
    private float priceTo;

    public float getPriceFrom() {
        return priceFrom;
    }

    public void setPriceFrom(float priceFrom) {
        this.priceFrom = priceFrom;
    }

    public float getPriceTo() {
        return priceTo;
    }

    public void setPriceTo(float priceTo) {
        this.priceTo = priceTo;
    }

    public String getPlaceNameString() {
        return placeNameString;
    }

    public void setPlaceNameString(String placeNameString) {
        this.placeNameString = placeNameString;
    }

    public List<Hotels> getListHotel() {
        return listHotel;
    }

    public void setListHotel(List<Hotels> listHotel) {
        this.listHotel = listHotel;
    }

    public String getSearchHotelString() {
        return searchHotelString;
    }

    public void setSearchHotelString(String searchHotelString) {
        this.searchHotelString = searchHotelString;
    }

    public String searchHotelAction() {
        try {
            listHotel = hotelsBusiness.advanceSearchHotel(searchHotelString, placeNameString, priceFrom, priceTo);
            return "infomationdesk.xhtml";
        } catch (Exception e) {
            return "infomationdesk.xhtml";
        }

    }
//----------------------------Search Flight-------------------------------------
    private List<Flight> listFlight;
    private Date dateFrom;
    private Date dateTo;
    private String departLocal;
    private String arrLocal;

    public String getArrLocal() {
        return arrLocal;
    }

    public void setArrLocal(String arrLocal) {
        this.arrLocal = arrLocal;
    }

    public String getDepartLocal() {
        return departLocal;
    }

    public void setDepartLocal(String departLocal) {
        this.departLocal = departLocal;
    }

    public List<Flight> getListFlight() {
        return listFlight;
    }

    public void setListFlight(List<Flight> listFlight) {
        this.listFlight = listFlight;
    }

    public Date getDateFrom() {
        return dateFrom;
    }

    public void setDateFrom(Date dateFrom) {
        this.dateFrom = dateFrom;
    }

    public Date getDateTo() {
        return dateTo;
    }

    public void setDateTo(Date dateTo) {
        this.dateTo = dateTo;
    }

    private String formatDateFrom(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
        try {
            String dateString = formatter.format(date);
            return dateString;
        } catch (NullPointerException npe) {
            return "";
        }
    }

    public String searchFlightAction() {
        listFlight = flightBusiness.advanceSearchFlight(departLocal, arrLocal, formatDateFrom(dateFrom), formatDateFrom(dateTo));
        return "infomationdesk.xhtml";
    }
//----------------------------Search Car ---------------------------------------
    private List<CarDetails> listCar;
    private String carName;
    private float priceFromCar;
    private float priceToCar;

    public float getPriceFromCar() {
        return priceFromCar;
    }

    public void setPriceFromCar(float priceFromCar) {
        this.priceFromCar = priceFromCar;
    }

    public float getPriceToCar() {
        return priceToCar;
    }

    public void setPriceToCar(float priceToCar) {
        this.priceToCar = priceToCar;
    }

    public String getCarName() {
        return carName;
    }

    public void setCarName(String carName) {
        this.carName = carName;
    }

    public List<CarDetails> getListCar() {
        return listCar;
    }

    public void setListCar(List<CarDetails> listCar) {
        this.listCar = listCar;
    }

    public String searchCarByNameAction() {
        listCar = carDetailBusiness.advanceSearchCar(carName, priceFromCar, priceToCar);
        return "infomationdesk.xhtml";
    }

//----------------------------Search Tour ---------------------------------------
    private List<PackageTour> listPackageTour;
    private String tourName;
    private float priceFromTour;
    private float priceToTour;

    public List<PackageTour> getListPackageTour() {
        return listPackageTour;
    }

    public void setListPackageTour(List<PackageTour> listPackageTour) {
        this.listPackageTour = listPackageTour;
    }

    public float getPriceFromTour() {
        return priceFromTour;
    }

    public void setPriceFromTour(float priceFromTour) {
        this.priceFromTour = priceFromTour;
    }

    public float getPriceToTour() {
        return priceToTour;
    }

    public void setPriceToTour(float priceToTour) {
        this.priceToTour = priceToTour;
    }

    public String getTourName() {
        return tourName;
    }

    public void setTourName(String tourName) {
        this.tourName = tourName;
    }

    public String searchAdvanceTourAction() {
        listPackageTour = tourBusiness.advanceSearchTour(tourName, priceFromTour, priceToTour);
        return "infomationdesk.xhtml";
    }


    /** Creates a new instance of CustomerSearchBean */
    public CustomerSearchBean() {
    }
}
